/*
 * @lc app=leetcode.cn id=258 lang=javascript
 *
 * [258] 各位相加
 */

// @lc code=start
/**
 * @param {number} num
 * @return {number}
 */
var addDigits = function(num) {
    num = num + ''
    if (num.length > 1) {
        let newNum = 0
        for (let index = 0; index < num.length; index++) {
            const element = num[index];
            newNum += Number(element)
        }
        num = newNum
        return addDigits(num)
    } else {
        return num
    }
};
// @lc code=end

